﻿using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using Aecg.OwinSelfHostServer.Service.Dto;

namespace Aecg.OwinSelfHostServer.Service.Controllers
{
    /// <summary>
    ///     Represents controller that exposes routes for error viewing.
    /// </summary>
    [ApiExplorerSettings(IgnoreApi = false)]
    public class ErrorController : ApiControllerBase
    {
        /// <summary>
        ///     Intercepts rout not found error in order to show it as friendly message on the screen.
        /// </summary>
        /// <param name="path">Path.</param>
        /// <returns>404 with <see cref="ErrorInfoModel" /> object as content.</returns>
        [HttpGet]
        [HttpPost]
        [HttpPut]
        [HttpPatch]
        [HttpDelete]
        [HttpHead]
        [HttpOptions]
        public HttpResponseMessage NotFound(string path)
        {
            var metadata = new ResponseDtoBase
            {
                ResponseCode = "404"
            };
            return Request.CreateResponse(HttpStatusCode.NotFound, metadata);
        }
    }
}